﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DHQGHN.PM0.Common.Attributes;
using WebMatrix.WebData;

namespace DHQGHN.PM0.Controllers
{
    public class HomeController : BaseController
    {
        log4net.ILog logger = log4net.LogManager.GetLogger(typeof(HomeController));
        //[Authorize]
        public ActionResult Index()
        {
            try
            {
                return View();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw;
            }
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult AjaxValidateToken()
        {
            return View();
        }

        [AjaxValidateAntiForgeryToken]
        public JsonResult PostSampleAction(string name)
        {
            return this.Json("Post Passed Validation -" + name);
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        [HttpGet]
        public ActionResult DowloadFile(string fileName)
        {
            try
            {
                if (System.IO.Path.GetExtension(fileName) == ".pdf")
                {
                    string fullPath = System.IO.Path.Combine(Server.MapPath("~/Content/files/"), fileName);

                    return File(fullPath, "application/pdf", fileName);
                }
                else
                {
                    return new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw;
            }
        }
    }
}